const app = getApp();
var config = require('../../utils/parts');
var header = getApp().request("header");
var requestUrl = getApp().request("url");
var resourceUrl = getApp().request("imgUrl");
var param=null;
Page({
  data: {
    installed: false,   //是否有已安装配件
    installable: false,   //是否有可安装配件
    newParts: -3000,//新配件与老配件差值
    hasInstalledParts: false,//当前部位是否已经有安装过的配件
    install_switch: true,//安装配件开关
    change_switch: true,//更换配件开关
    sale_switch: true,//卖出配件开关
    baseRequestUrl: config.apiUrl,//线上接口地址
    baseImgUrl: config.imgUrl,//图片地址
    goldcoin: 0,//用户金币数量
    getCoinShow: false,//获取金币弹窗
    coin2baoItem: 0,//金币兑换大通宝选中条目
    close_success: false,  //兑换成功
    success_gold: "1000",
    dtbArr: [5, 25, 50, 250],
    //=====================================================
    //已装配部分
    installed_imgUrl: '',
    installed_name: '',
    installed_score: '',
    installed_spend: 0,
    //=====================================================
    partsItem: [],
    resourceUrl: resourceUrl ,
    isSuit:false,      //套装是否显示
    suitStar:"",       //套装星级
    suitCar:"",        //套装车
    suitColor:""       //套装颜色
  },
  onLoad: function (option) {
    param = option.act;
  },
  onShow: function () {
    this.pageRendering(param);
    this.setData({
      isSuit: false
    })
    wx.showShareMenu({
      withShareTicket: true
    });
  },
  getCoinShow() {
    this.setData({
      getCoinShow: true
    })
  },
  tocoin2bao: function () {
    this.setData({
      getCoinShow: false,
      coin2bao: true
    })
  },
  //立即兑换大通宝按钮
  btnNowExchange() {
    var that = this;
    //未选中金币不能兑换
    if (this.data.coin2baoItem == 0) { return }
    var dtbArr = this.data.dtbArr;     //大通宝数组
    var dtbItem = this.data.coin2baoItem - 1;  //选中的哪个大通宝
    var dtbNum = dtbArr[dtbItem];              //选中的大通宝数量
    //请求大通宝和是否登录
    wx.showLoading({
      title: ' ',
      mask: true
    });
    wx.request({
      url: requestUrl + 'baoExchangeGold',
      method: "POST",
      data: { userId: app.globalData.session_key.userId, salt: app.globalData.session_key.salt, bao: dtbNum },
      header: header,
      success: (res) => {
        if (res.statusCode != 200) {
          getApp().showModal("服务器异常");
          return
        }
        wx.hideLoading();
        if (res.data.code == 200) {
          //data大金币数量增加
          var goldcoin = this.data.goldcoin;
          goldcoin += dtbNum * 200;
          //本地存储的金币相应增加
          app.globalData.gold = goldcoin;
          that.setData({
            coin2bao: false,   //关闭窗口
            coin2baoItem: 0,    //大通宝选项初始化
            goldcoin: goldcoin,  //金币数量
            success_gold: dtbNum * 200,
            close_success: true
          });
          //提示成功
        } else if (res.data.code == 402) {
          getApp().showModal("提交大通宝数量有误！");
        } else if (res.data.code == 401 || res.data.code == 301 || res.data.code == 302) {
          getApp().showModal("系统信息有误，请重试！");
        } else if (res.data.code == 304) {
          getApp().showModal("大通宝余额不足！");
        } else if (res.data.code == 305) {
          getApp().showModal("大通宝余额不足！");
        } else if (res.data.code == 306) {
          getApp().showModal("大通宝兑换金币失败，请重试！");
        } else if (res.data.code == 303) {
          wx.navigateTo({
            url: '../login/login?url=index'
          })
        } else if (res.data.code == 800) {
          getApp().showModal(res.data.data.msg);
          wx.hideLoading();
        }

      },
      fail: function (res) {
        console.log("大通宝接口fail");
        console.log(res);
        wx.hideLoading();
        getApp().showModal("网络超时，请检查您的网络");
      }
    });
  },
  toWarehousePage() {
    this.setData({
      getCoinShow: false
    })
    wx.navigateTo({
      url: '../warehouse/warehouse'
    })
  },
  coin2bao: function (event) {
    var num = event.target.dataset.num;
    if (this.data.coin2baoItem == num) {
      this.setData({
        coin2baoItem: 0
      })
    } else {
      this.setData({
        coin2baoItem: num
      })
    }
  },
  closeView: function (event) {
    var name = event.target.dataset.name;
    this.setData({
      [name]: false
    })
    if (event.target.id === 'intro') {
      wx.setStorage({
        key: 'intro',
        data: true
      })
    }
  },
  pageRendering: function (param) {
    //页面渲染
    var _this = this;
    var gold = app.globalData.gold,
      car = app.globalData.car,
      depot = app.globalData.depot,
      score = app.globalData.score;
    _this.setData({
      goldcoin: gold,
      car: car,
      score: score,
      depot: depot
    })

    //判断该插槽是否装有配件
    var total_parts = car[0][param];
    console.log(total_parts)
    if (total_parts != '') {
      _this.setData({
        installed: true,
        hasInstalledParts: true
      })
      var total_url = _this.getImgUrl(total_parts),
        name = _this.getName(total_parts),
        score = _this.getScore(total_parts),
        uninstallPrice = _this.getDownPrice(total_parts, score);

      _this.setData({
        installed_imgUrl: total_url,
        installed_name: name,
        installed_score: score,
        installed_spend: uninstallPrice,
        installed_sign: total_parts,
        installed_star: total_parts[1]
      })
    } else {
      _this.setData({
        installed: false
      })
    }

    //判断仓库有没有该位置的配件
    var thisPartsArr = [];
    for (var key in depot) {
      if (key[0] == param && depot[key] != 0) {
        thisPartsArr.push(key);
      }
    }
    if (thisPartsArr.length != 0) {
      _this.setData({
        installable: true
      });
      var configArr = [];
      for (var i = 0; i < thisPartsArr.length; i++) {
        var obj = {};
        obj.src = _this.data.baseImgUrl + '/parts/' + thisPartsArr[i][0] + '/' + thisPartsArr[i] + '_small.png?111';
        obj.name = _this.getName(thisPartsArr[i]);
        obj.score = _this.data.score;
        obj.partsScore = _this.getScore(thisPartsArr[i]);
        obj.newScore = obj.partsScore - _this.data.installed_score;
        obj.repackPay = _this.getRepackPay(thisPartsArr[i], obj.partsScore);
        obj.sign = thisPartsArr[i];

        var times = depot[thisPartsArr[i]];
        for (var j = 0; j < times; j++) {
          configArr.push(obj);
        }
      }

      _this.setData({
        partsItem: configArr
      })
    } else {
      _this.setData({
        installable: false
      })
    }
  },
  //是否是套装
  isSuit(){
    var carSuit=app.globalData.car[0];
    var suit6=[];
    var suitArr=["b","c","d","e","f","g"];
    for (var i= 0;i < suitArr.length;i++){
      suit6.push(carSuit[suitArr[i]]);
    }
    console.log(suit6)
    var starArr = ["一", "两", "三", "四", "五"];
    var starNum=0;
    //判断星级
    for (var i = 0; i < suit6.length-1;i++){
      if (suit6[i][1] == suit6[i+1][1]){
        starNum++;
        if (starNum==5){
          //判断颜色
          var colorNum=0;
          for (var i = 0; i < suit6.length - 1; i++) {
            if (suit6[i][2] == suit6[i + 1][2]) {
              colorNum++;
              if (colorNum == 5) {
                if (suit6[0][1] == suit6[0][2]){
                  wx.showLoading({
                    title: '',
                    mask:true
                  })
                  //请求后端查看配件是否是套装
                  wx.request({
                    url: requestUrl + 'isNewSuit',
                    method: "POST",
                    data: { userId: app.globalData.session_key.userId, salt: app.globalData.session_key.salt},
                    header: header,
                    success: (res) => {
                      if (res.statusCode != 200) {
                        getApp().showModal("服务器异常");
                        return
                      }
                      wx.hideLoading();
                      if (res.data.code == 200) {
                        var star = starArr[suit6[0][1] - 1];
                        var color = config.color[suit6[0][2] - 1];
                        this.setData({
                          suitCar: suit6[0].slice(1),
                          suitStar: star,
                          suitColor: color,
                          isSuit: true
                        });
                        this.pageRendering(param); 
                      } else if (res.data.code == 201) {
                        wx.showToast({
                          title: '安装成功',
                          icon: 'success',
                          duration: 1500,
                          success: function () {
                            wx.navigateBack({
                              delta: 1
                            });
                          }
                        });
                        this.pageRendering(param); 
                      } else if (res.data.code == 401 || res.data.code == 301 || res.data.code == 302) {
                        getApp().showModal("提交信息有误" + res.data.code);
                      } else if (res.data.code == 303) {
                        getApp().showModal("你还未买车");
                      } else if (res.data.code == 304) {
                        getApp().showModal("当前车辆配件不符合条件");
                      } else if (res.data.code == 800) {
                        getApp().showModal(res.data.data.msg);
                      }

                    },
                    fail: function (res) {
                      console.log("套装接口failed");
                      console.log(res);
                      wx.hideLoading();
                      getApp().showModal("网络超时，请检查您的网络");
                    }
                  });
                }else{
                  wx.showToast({
                    title: '安装成功',
                    icon: 'success',
                    duration: 1500,
                    success: function () {
                      wx.navigateBack({
                        delta: 1
                      });
                    }
                  });
                }
              }
            } else {
              wx.showToast({
                title: '安装成功',
                icon: 'success',
                duration: 1500,
                success: function () {
                  wx.navigateBack({
                    delta: 1
                  });
                }
              });
              break;
            }
          }
        }
      }else{
        wx.showToast({
          title: '安装成功',
          icon: 'success',
          duration: 1500,
          success: function () {
            wx.navigateBack({
              delta: 1
            });
          }
        });
        break;
      }
    }
  },
  btnGetPrize(){
    wx.navigateTo({
      url: '../warehouse/warehouse?id=suit'
    })
  },
  //使用
  useParts: function (event) {
    var _this = this;
    var parts = event.target.dataset.name;
    var price = event.target.dataset.price;
    if (price > app.globalData.gold) {
      wx.showToast({
        title: '金币不足',
        icon: 'none',
        duration: 1000
      });
      return false;
    }
    console.log(app.globalData.car)
    wx.showLoading({
      title: '',
      mask: true
    });
    wx.request({
      url: _this.data.baseRequestUrl + 'installParts',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      data: {
        userId: app.globalData.session_key.userId,
        salt: app.globalData.session_key.salt,
        carTypeId: _this.data.car[0].type,
        parts: parts
      },
      success: function (res) {
        if (res.statusCode != 200) {
          getApp().showModal("服务器异常");
          return
        }
        switch (res.data.code) {
          case 200:
            var goal;
            for (var i = 0; i < _this.data.partsItem.length; i++) {
              if (_this.data.partsItem[i].src.indexOf(parts) > 0) {
                goal = _this.data.partsItem[i]
              }
            }

            var now_gold = _this.data.goldcoin - goal.repackPay,
              now_score = Number(_this.data.score) + Number(goal.newScore);

            var now_depot = _this.data.depot,
              now_depot_parts = _this.data.depot[parts];
            if (now_depot_parts - 1 != 0) {
              now_depot[parts] = now_depot_parts - 1;
            } else {
              delete now_depot[parts];
            }
            var now_car = _this.data.car;
            now_car[0][parts[0]] = parts;

            app.globalData.score = now_score;
            app.globalData.car = now_car;
            app.globalData.gold = now_gold;
            app.globalData.depot = now_depot;
            _this.isSuit();
            // wx.showToast({
            //   title: '安装成功',
            //   icon: 'success',
            //   duration: 1500,
            //   success: function () {
            //     wx.navigateBack({
            //       delta: 1
            //     });
            //   }
            // });
            wx.hideLoading();
            
            
            break;
          case 401:
            wx.showToast({
              title: '空值',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 402:
            wx.showToast({
              title: 'carTypeId为空',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 301:
            wx.showToast({
              title: 'userId错误',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 302:
            wx.showToast({
              title: 'salt错误',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
          case 303:
            wx.showToast({
              title: '金币不足',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 304:
            wx.showToast({
              title: '你没有这个配件',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 305:
            wx.showToast({
              title: '你没有这辆车',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 306:
            wx.showToast({
              title: '这个位置已经有配件了',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 800:
            getApp().showModal(res.data.data.msg);
            wx.hideLoading();
            break;
          default:
            console.log('%c安装配件返回接口错误', 'background:rgba(0,0,0,0.1);color:red');
            wx.hideLoading();
            break;
        }
       
      },
      fail: function (res) {
        console.log("安装配件接口fail");
        console.log(res);
        wx.hideLoading();
        getApp().showModal("网络超时，请检查您的网络");
      }
    })
  },
  //更换
  changeParts: function (event) {
    var _this = this;
    var price = event.target.dataset.price;
    var parts = event.target.dataset.name;
    if (price > app.globalData.gold) {
      wx.showToast({
        title: '金币不足',
        icon: 'none',
        duration: 1000
      });
      return false;
    }
    if (parts == _this.data.car[0][parts[0]]){
      wx.showToast({
        title: '相同配件不能更换哦！',
        icon: 'none',
        duration: 1000
      });
      return false;
    }
    wx.showLoading({
      title: '',
      mask: true
    });
    
    wx.request({
      url: _this.data.baseRequestUrl + 'replaceParts',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      data: {
        userId: app.globalData.session_key.userId,
        salt: app.globalData.session_key.salt,
        carTypeId: _this.data.car[0].type,
        partsUp: parts,
        partsDown: _this.data.car[0][parts[0]]
      },
      success: function (res) {
        if (res.statusCode != 200) {
          getApp().showModal("服务器异常");
          return
        }
        switch (res.data.code) {
          case 200:
            var goal;//寻找已装配的该位置的配件
            for (var i = 0; i < _this.data.partsItem.length; i++) {
              if (_this.data.partsItem[i].src.indexOf(parts) > 0) {
                goal = _this.data.partsItem[i]
              }
            }

            var now_gold = _this.data.goldcoin - goal.repackPay - _this.data.installed_spend,
              now_score = Number(_this.data.score) + Number(goal.newScore);

            var now_depot = _this.data.depot,
              now_depot_parts = _this.data.depot[parts],
              old_depot_parts = _this.data.car[0][parts[0]],
              old_depot_parts_num = _this.data.depot[old_depot_parts] || 0;
            if (now_depot_parts - 1 != 0) {
              now_depot[parts] = now_depot_parts - 1;
            } else {
              delete now_depot[parts];
            }
            now_depot[old_depot_parts] = Number(old_depot_parts_num) + 1;
            var now_car = _this.data.car;
            now_car[0][parts[0]] = parts;

            app.globalData.score = now_score;
            app.globalData.car = now_car;
            app.globalData.gold = now_gold;
            app.globalData.depot = now_depot;
            _this.isSuit();
            wx.hideLoading();
            break;
          case 401:
            wx.showToast({
              title: '空值',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 402:
            wx.showToast({
              title: 'carTypeId为空',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 403:
            wx.showToast({
              title: '更换的配件类型不一致',
              icon: "none",
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 404:
            wx.showToast({
              title: '相同配件不能更换哦！',
              icon: "none",
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 301:
            wx.showToast({
              title: 'userId错误',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 302:
            wx.showToast({
              title: 'salt错误',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
          case 303:
            wx.showToast({
              title: '金币不足',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 304:
            wx.showToast({
              title: '你没有这辆车',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 305:
            wx.showToast({
              title: '这个位置并没有配件',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 306:
            wx.showToast({
              title: '该车该配件栏已装配件与传参partsDown不符合',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 307:
            wx.showToast({
              title: '仓库中并没有你想更换的配件',
              icon: 'none',
              duration: 1000
            });
            wx.hideLoading();
            break;
          case 800:
            getApp().showModal(res.data.data.msg);
            wx.hideLoading();
            break;
          default:
            console.log('%c更换配件接口返回错误', 'background:rgba(0,0,0,0.1);color:red');
            wx.hideLoading();
            break;
        }

      },
      fail: function (res) {
        console.log("更改配件接口fail");
        console.log(res);
        wx.hideLoading();
        getApp().showModal("网络超时，请检查您的网络");
      }
    })
  },
  //卖出
  saleParts: function (event) {
    var _this = this;
    wx.showLoading({
      title: '',
      mask: true
    });
    var parts = event.target.dataset.name;
    wx.request({
      url: _this.data.baseRequestUrl + 'sellParts',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      data: {
        userId: app.globalData.session_key.userId,
        salt: app.globalData.session_key.salt,
        parts: parts,
      },
      success: function (res) {
        if (res.statusCode != 200) {
          getApp().showModal("服务器异常");
          return
        }
        switch (res.data.code) {
          case 200:
            var goal;//寻找已装配的该位置的配件
            for (var i = 0; i < _this.data.partsItem.length; i++) {
              if (_this.data.partsItem[i].src.indexOf(parts) > 0) {
                goal = _this.data.partsItem[i]
              }
            }
            var now_gold = _this.data.goldcoin + _this.getSalePrice(parts);
            var now_depot = _this.data.depot,
              now_depot_parts = _this.data.depot[parts];

            if (now_depot_parts - 1 != 0) {
              now_depot[parts] = now_depot_parts - 1;
            } else {
              delete now_depot[parts];
            }

            app.globalData.gold = now_gold;
            app.globalData.depot = now_depot;

            wx.showToast({
              title: '卖出成功',
              icon: 'success',
              duration: 1500,
              success: function () {
                wx.navigateBack({
                  delta: 1
                });
              }
            });
            break;
          case 401:
            wx.showToast({
              title: '空值',
              icon: 'none'
            });
            wx.hideLoading();
            break;
          case 301:
            wx.showToast({
              title: 'userId错误',
              icon: 'none',
            });
            wx.hideLoading();
            break;
          case 302:
            wx.showToast({
              title: 'salt错误',
              icon: 'none'
            });
            wx.hideLoading();
          case 303:
            wx.showToast({
              title: '仓库中没有该配件',
              icon: 'none'
            });
            wx.hideLoading();
            break;
          case 800:
            getApp().showModal(res.data.data.msg);
            wx.hideLoading();
            break;
          default:
            console.log('%c卖出配件接口返回错误', 'background:rgba(0,0,0,0.1);color:red');
            wx.hideLoading();
            break;
        }

      },
      fail: function (res) {
        console.log("卖出配件fail");
        console.log(res);
        wx.hideLoading();
        getApp().showModal("网络超时，请检查您的网络");
      }
    })
  },
  //卸载
  unloadParts: function (event) {
    var _this = this;
    var price = event.target.dataset.price;
    var depot = app.globalData.depot;
    if (Object.keys(depot).length > 48) {
      wx.showToast({
        title: '仓库已满，请先卖出',
        icon: 'none',
        duration: 1000
      });
      return false;
    }
    if (price > app.globalData.gold) {
      wx.showToast({
        title: '金币不足',
        icon: 'none',
        duration: 1000
      });
      return false;
    }
    wx.showLoading({
      title: '',
      mask: true
    });
    var parts = event.target.dataset.name;
    wx.request({
      url: _this.data.baseRequestUrl + 'unloadParts',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      data: {
        userId: app.globalData.session_key.userId,
        salt: app.globalData.session_key.salt,
        parts: parts,
        carTypeId: _this.data.car[0].type
      },
      success: function (res) {
        if (res.statusCode != 200) {
          wx.hideLoading();
          getApp().showModal("服务器异常");
          return
        }
        switch (res.data.code) {
          case 200:

            var goal;//寻找已装配的该位置的配件
            for (var i = 0; i < _this.data.partsItem.length; i++) {
              if (_this.data.partsItem[i].src.indexOf(parts) > 0) {
                goal = _this.data.partsItem[i]
              }
            }

            var now_gold = _this.data.goldcoin - _this.data.installed_spend,
              now_score = _this.data.score - _this.data.installed_score;

            var now_depot = _this.data.depot,
              now_depot_parts = _this.data.depot[parts] || 0;

            now_depot[parts] = now_depot_parts + 1;

            var now_car = _this.data.car;
            now_car[0][parts[0]] = '';

            app.globalData.gold = now_gold;
            app.globalData.depot = now_depot;
            app.globalData.car = now_car;
            app.globalData.score = now_score;
            wx.showToast({
              title: '卸下成功',
              icon: 'success',
              duration: 1500,
              success: function () {
                wx.navigateBack({
                  delta: 1
                });
              }
            });
            break;
          case 401:
            wx.showToast({
              title: '空值',
              icon: 'none'
            });
            wx.hideLoading();
            break;
          case 301:
            wx.showToast({
              title: 'userId错误',
              icon: 'none',
            });
            wx.hideLoading();
            break;
          case 302:
            wx.showToast({
              title: 'salt错误',
              icon: 'none'
            });
            wx.hideLoading();
          case 303:
            wx.showToast({
              title: '仓库已满，请先卖出',
              icon: 'none'
            });
            wx.hideLoading();
            break;
          case 304:
            wx.showToast({
              title: '金币不足',
              icon: 'none'
            });
            wx.hideLoading();
            break;
          case 305:
            wx.showToast({
              title: '你没有这辆车',
              icon: 'none'
            });
            wx.hideLoading();
            break;
          case 306:
            wx.showToast({
              title: '这里没有配件',
              icon: 'none'
            });
            wx.hideLoading();
            break;
          case 307:
            wx.showToast({
              title: '该车该配件栏已装配件与传参parts不符合',
              icon: 'none'
            });
            wx.hideLoading();
          case 800:
            getApp().showModal(res.data.data.msg);
            wx.hideLoading();
          default:
            console.log('%c卸下配件接口返回错误', 'background:rgba(0,0,0,0.1);color:red');
            wx.hideLoading();
            break;
        }
      },
      fail: function (res) {
        console.log("卸载配件接口fail");
        console.log(res);
        wx.hideLoading();
        getApp().showModal("网络超时，请检查您的网络");
      }
    })
  },
  setStorage: function (name, data) {
    //设置本地存储
    wx.setStorage({
      key: name,
      data: data,
      success: function () {
        console.log("%c存储用户" + name + "成功", 'background:#017b40;color:#fff');
      },
      fail: function (res) {
        console.log('%c存储用户' + name + '失败!\n' + res, 'background:rgba(0,0,0,0.1);color:red');
      }
    })
  },
  getImgUrl: function (str) {
    return this.data.baseImgUrl + '/parts/' + str[0] + '/' + str + '_small.png?111'
  },
  getName: function (str) {
    var res = '';
    if (str[0] == 'h') {
      res = config.h[str[1]][str[2]].name;
    } else if (str[0] == 'a') {
      res = config.a[str[1]].name;
    } else {
      res = config[str[0]][str[1]].name + '（' + config.color[str[2] - 1] + '）';
    }

    return res
  },
  getScore: function (str) {
    var baseAttribute = config.getBaseAttribute(str[0], str[1]);
    var colorAddition;
    if (str[0] == 'a' || str[0] == 'h') {
      colorAddition = 0;
    } else {
      colorAddition = config.getColorAddition(str[2]);
    }
    var res = config.getPartsScore(str[1], colorAddition, baseAttribute);
    return res
  },
  getSalePrice: function (str) {
    var partsScore = this.getScore(str);
    return partsScore * 0.4
  },
  getDownPrice: function (str, score) {
    var baseAttribute = config.getBaseAttribute(str[0], str[1]);
    var installPrice = config.getInstallPrice(baseAttribute, score);
    var res = config.getUninstallPrice(installPrice);

    return res
  },
  getRepackPay: function (str, score) {
    var baseAttribute = config.getBaseAttribute(str[0], str[1]);
    var res = config.getInstallPrice(baseAttribute, score);

    return res
  },
  /**
 * 用户点击右上角分享
 */
  onShareAppMessage: function (res) {
    //是否选车
    var fightCarTypeId = app.globalData.fightCarTypeId;
    //随机一句宣言
    var declaration = getApp().Refit();
    var myRefitTxt = Math.floor(Math.random() * declaration.length);
    if (fightCarTypeId == 0) {
      return {
        title: getApp().shareTitle1(),
        path: "/pages/index/index"
      }
    } else {
      return {
        title: getApp().shareTitle2(),
        path: "/pages/openShare/openShare?shareId=" + app.globalData.session_key.userId + "&carTypeId=" + fightCarTypeId + "&shareRefitNum=" + myRefitTxt + "&carName=SUV概念车",
        success: (re) => {
          if (Object.keys(re).length == 1) {
            return
          }
          var ticket = re.shareTickets[0];
          getApp().shareFn(ticket);
        }
      }
    }
  },
})